package com.lagou.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Controller
public class FileUploadController {
    @RequestMapping("/fileUpload")
    public String fileUpload(String username, MultipartFile filePic){
        System.out.println(username);
        String originalFilename = filePic.getOriginalFilename();
        try {
            filePic.transferTo(new File("D:\\uploadTest\\" + originalFilename));
        } catch (IOException e) {
            e.printStackTrace();
        }

        return "quick";
    }

    @RequestMapping("/fileUploads")
    public String fileUploads(String username, MultipartFile[] filePic){
        System.out.println(username);

        for (MultipartFile multipartFile : filePic) {
            String originalFilename = multipartFile.getOriginalFilename();
            try {
                multipartFile.transferTo(new File("D:\\uploadTest\\" + originalFilename));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return "quick";
    }
}
